#include "cdocktip.h"

#include <buola/image/cgc.h>
#include <buola/image/cfont.h>

namespace buola { namespace bdesktop {

CDockTip::CDockTip()
    :   mRealPos(CPoint(nUndefined)),
        mPosValid(false)
{
    SetWMMode(WM_STICKY|WM_NOMANAGING);
    SetPaintMode(PAINT_TRANSPARENT);
}

void CDockTip::SetCaption(const std::wstring &pCaption)
{
    mCaption=pCaption;
    CSize lSize(mFont->GetWidth(mCaption)+10,mFont->GetHeight()+20);
    MoveResize(CPoint(mRealPos.x-lSize.x/2,mRealPos.y-lSize.y+10),lSize);
}

void CDockTip::SetPos(const CPoint &pPos)
{
    if(mRealPos==pPos) return;
    mRealPos=pPos;
    Move(CPoint(mRealPos.x-GetSize().x/2,mRealPos.y-GetSize().y));
}

void CDockTip::OnCreate()
{
    SetBackNone();
    mFont=CFont::GetStock(L"control");
}

void CDockTip::OnExpose(gui::CExposeEvent *pE)
{
    CGC *lGC=pE->mGC;
    lGC->SetFont(mFont);
    lGC->SetSourceColor(RGBA(40,40,40,220));
    lGC->RoundRect(CRect(mRect.l+1,mRect.t+1,mRect.r-1,mRect.b-11),5);
    lGC->MoveTo(CPoint((mRect.l+mRect.r)/2-10,mRect.b-11));
    lGC->LineTo(CPoint((mRect.l+mRect.r)/2+10,mRect.b-11));
    lGC->LineTo(CPoint((mRect.l+mRect.r)/2,mRect.b-2));
    lGC->ClosePath();
    lGC->FillPath();
    lGC->SetSourceColor(RGB(255,255,255));
    lGC->DrawText(CPoint(5,5),mCaption);
}

void CDockTip::OnSize(gui::CGeometryEvent*)
{
}

void CDockTip::OnAnimationTimer()
{
}

/*namespace bdesktop*/ } /*namespace buola*/ }
